<template>
    <div class="config">
        <DashHeader/>
        <el-main>
        <el-table :data="list" style="width: 100%">
        <el-table-column prop="PlanID" label="记录号" width="120"></el-table-column>
        <el-table-column prop="PlanProduct" label="测试产品" width="100"></el-table-column>
        <el-table-column prop="PlanEnv" label="测试环境" width="100"></el-table-column>
        <el-table-column prop="PlanType" label="测试类型" width="150"></el-table-column> 
        <el-table-column prop="PlanModel" label="测试模块" width="150"></el-table-column>        
        <el-table-column prop="PlanPassCase" label="通过用例" width="100"></el-table-column>
        <el-table-column prop="PlanFailCase" label="失败用例" width="100"></el-table-column> 
        <el-table-column prop="CreatedAt" label="测试开始时间" width="160"></el-table-column>
        <el-table-column prop="UpdatedAt" label="测试结束时间" width="160"></el-table-column> 
         <el-table-column prop="PlanStatus" label="测试状态" width="100"></el-table-column>
             <el-table-column prop="PlanResult" label="测试结果" width="100"></el-table-column>
        <el-table-column  label="测试报告" width="150">
            <template v-slot="scope">  
             <el-button type="success" @click="gotoReport(scope.row)" icon="el-icon-search" >查看</el-button>
            </template>
        </el-table-column>
        </el-table>
        </el-main>
    </div>

</template>

<script>
import  DashHeader  from '@/components/DashHeader'
export default {
   name: 'ReportList',
   components: {
       DashHeader
   },
   data() {
       return {
           list: [],
       }
   },
   methods: {
      formatDate(timestamp) {
  return timestamp.replace(/T/g,' ').replace(/Z/g,'')
},
       gotoReport(list) { 
            console.log(list.PlanStatus)
           if (list.PlanStatus === "测试进行中") {
           console.log("good")
            var message =  '测试进行中'
           this.$alert(message, '测试执行中', {
          confirmButtonText: '确定',
            callback: () => {
            this.$message({
              type: 'info',
              message: `测试进行中`,
            })
          }, 
        })
           } else {
           console.log(list) 
           if (list.PlanType === "performance")  {
               //性能测试就跳转到外部链接
                window.location.href = list.PlanResultUrl;
           } else {
               //功能测试内链到iframe
                this.$router.push({
                   path: '/platform/report/reportdetail',
                   query: { planresult: list.PlanResultUrl}
               })    
           }
                   
       }
   }},
   mounted() {
       this.$http.get('/api/v1/operation/planlist').then(resp => {
           const tmpdata = resp.data
           const nn = tmpdata.length
           for (var i=0;i<nn;i++) {              
                   //window.console.log(tmpdata[i])
                   tmpdata[i].CreatedAt = this.formatDate(tmpdata[i].CreatedAt)
                   tmpdata[i].UpdatedAt = this.formatDate(tmpdata[i].UpdatedAt)
                   if (tmpdata[i].PlanStatus) {
                       tmpdata[i].PlanStatus = "测试完成"
                   } else {
                       tmpdata[i].PlanStatus = "测试进行中"
                   }
                    if (tmpdata[i].PlanResult) {
                       tmpdata[i].PlanResult = "通过"
                   } else {
                       tmpdata[i].PlanResult = "失败"
                   }
                   this.list.push(tmpdata[i])              
           }
           this.list.sort(function(a,b){
               return b.PlanID - a.PlanID;
           })
       })
   }
}
</script>